package cn.lhn.ridersclub.mapper;

import cn.lhn.ridersclub.entity.Paper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PaperMapper extends BaseMapper<Paper> {

    @Select("select * from paper where id > ${startId} and title like concat('%', #{keyword}, '%') or connect like concat('%', #{keyword}, '%') order by id desc limit 6;")
    List<Paper> listByKeyword(@Param("keyword") String keyword, @Param("startId") Long startId);

    @Select("select * from paper where id < ${startId} and account_id = ${accountId} order by id desc limit 6;")
    List<Paper> listByAccountId(@Param("accountId") Long accountId, @Param("startId") Long startId);

    @Select("select * from paper order by rand() limit 0, 6;")
    List<Paper> listRandom();

    @Select("select * from paper where id < ${startId} and club_id = ${clubId} order by id desc limit 6;")
    List<Paper> listByClubId(@Param("clubId") Long clubId, @Param("startId") Long startId);

    @Select("select * from paper where account_id = ${accountId} order by id desc limit 1;")
    Paper getLastPaper(@Param("accountId") Long accountId);
}
